/**
* Trigger Name: ifulfillRestrictDeleteWFunction
* Author: Accenture 
* Date: 31-Jan-2012 
* Requirement/Project Name: iFulfill 
* Requirement Description: 'Workflow Function cannot be deleted if  workflow definition is not in Inactive status
**/

trigger ifulfillRestrictDeleteWFunction on Workflow_Stage__c (before delete) {

list<Workflow_Stage__c> wfList = new list<Workflow_Stage__c>();
list<Workflow_Definition__c> wdefinitionList = new list<Workflow_Definition__c>();
Set<ID> wfId = new Set<Id>();

 for(Workflow_Stage__c f: trigger.old)
 {
     wfId.add(f.Workflow_Code__c);
 }
 wdefinitionList =[Select Status__c from Workflow_Definition__c where id in :wfID and (Status__c = 'Active'or Status__c ='Pending Inactivation' or Status__c='Build In Progress') ];
 wfId.clear();
 for(Workflow_Definition__c wfObj: wdefinitionList)
 {
     wfId.add(wfObj.id);
 }  
 for(Workflow_Stage__c f: trigger.old)
 {
      if(wfID.contains(f.Workflow_Code__c))
      {
            f.adderror('Workflow Function cannot be deleted if  workflow definition is not in Inactive status');
      } 
 }
}